/*
 * NamedTag.cpp
 *
 *  Created on: 18 juin 2011
 *      Author: Pierrick Caillon <pierrick@megami.fr>
 */

#include "NamedTag.h"
#include "TagString.h"

namespace NamedBinaryTag
{

NamedTag::NamedTag() :
	ITag(), name(NULL)
{
}

NamedTag::~NamedTag()
{
	if (name != NULL)
		delete name;
}

std::string NamedTag::get_Name() const
{
	if (name == NULL)
		return std::string("");
	return name->get_Value();
}

void NamedTag::set_Name(std::string value)
{
	if (name == NULL)
		name = new TagString();
	name->set_Value(value);
}

void NamedTag::Read(std::istream &input)
{
	Read(input, false);
}

void NamedTag::Write(std::ostream &output) const
{
	Write(output, false);
}

void NamedTag::Read(std::istream &input, bool ignoreName)
{
	if (!ignoreName)
	{
		if (name == NULL)
			name = new TagString();
		name->Read(input, true);
	}
}

void NamedTag::Write(std::ostream &output, bool ignoreName) const
{
	if (!ignoreName)
	{
		if (name == NULL)
		{
			TagString tmp;
			tmp.Write(output, true);
		}
		else
			name->Write(output, true);
	}
}

}
